package com.ychug.gateway.system;

import com.ychug.framework.util.ServletUtils;
import com.ychug.framework.web.base.BaseController;
import com.ychug.service.system.entity.SysMenuEntity;
import com.ychug.service.system.entity.SysUserEntity;
import com.ychug.service.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 首页 业务处理
 *
 * @author dds
 */
@Controller
public class SysIndexController extends BaseController
{
    @Autowired
    private ISysMenuService menuService;

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap){

        SysUserEntity sysUserEntity = (SysUserEntity) ServletUtils.getSession().getAttribute("user");

        if(sysUserEntity == null || sysUserEntity.getUserName() == null){
            return "modules/sys/login";
        }

        // 取身份信息
        SysUserEntity user = getSysUser();
        // 根据用户id取出菜单
        List<SysMenuEntity> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", 2018);
        return "modules/sys/index";
    }

    @RequestMapping("/sys/main")
    public String mian(HttpServletRequest request, HttpServletResponse response){
        System.out.println("3434");
        return "include/main";
    }



}
